# -*- coding: utf-8 -*-
# @Time    : 2024/7/7 18:36
# @Author  : wangwei
# @File    : demo.py
import time

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

appium_server_url = 'http://127.0.0.1:4723/wd/hub'
caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:7555"
caps["appPackage"] = "com.tencent.mobileqq"
caps["appActivity"] = ".activity.SplashActivity"
caps["noReset"] = "true"
caps["ensureWebviewsHavePages"] = True

driver=webdriver.Remote(appium_server_url, caps)
driver.implicitly_wait(30)
# driver = webdriver.Remote("http://127.0.0.1:4724/wd/hub", caps)

# el1 = driver.find_element_by_accessibility_id("同意协议")
el1 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"同意协议")
el1.click()
el2 = driver.find_element(AppiumBy.ID,"com.tencent.mobileqq:id/n6y")
el2.click()
el3 = driver.find_element(AppiumBy.ACCESSIBILITY_ID,"账户及设置")
el3.click()
el4 = driver.find_element(AppiumBy.XPATH,"//*[@text=\"设置\"]")
el4.click()
el5 = driver.find_element(AppiumBy.XPATH,"//*[@text=\"账号管理\"]")
el5.click()
el6 = driver.find_element(AppiumBy.XPATH,"//*[@text=\"退出\"]")
el6.click()
els1 = driver.find_element(AppiumBy.XPATH,"//*[@text=\"退出登录\"]")
els1.click()
els2 = driver.find_element(AppiumBy.XPATH,"//*[@text=\"确定退出\"]")
els2.click()
try:
    assert ("我老婆是康雪" in driver.page_source)
except Exception as e:
    print(e.__str__())
try:
    assert driver.page_source.__contains__("我老婆是康雪")
except Exception as e:
    print(e.__str__())
time.sleep(5)




els1 = driver.find_elements_by_xpath("//*[@content-desc=\"百度搜索，请输入\"]")
els2 = driver.find_elements_by_xpath("//*[@text=\"请输入搜索关键词\"]")
els2[0].send_keys("自动化测试","自动化测试")

els3 = driver.find_elements_by_xpath("//*[@text=\"搜索\"]")
els4 = driver.find_elements_by_xpath("//*[@text=\"搜索\"]")
els5 = driver.find_elements_by_xpath("//*[@text=\"搜索\"]")
el2 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/com.baidu.searchbox.widget.SlidingPaneLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView")
el2.click()
